-
dmitsuki:
-
All an array is, is if you have a starting address 0, and an int is 4 bytes wide, if you index into the array for the second position, start at the first position and go 4 bytes (4 * 1)
-
To get the third position it would be 4 * 2, etc. That's all an "array" is: a pointer, and then you do math to its address
-
-
Caio:
-
That sounds so weird, it seems like I'm just scrolling through memory without much consideration for typing or any boundary checking. Idk, maybe this is the way it is in the end, but sounds odd to me at first.
-
So you can happily store beyond the bounds of an array because, to the CPU, it's just another pointer address. Bounds checking and such is enforced at a higher level (i.e., the language that generated the instructions)
-
-
Lee:
-
Rest assured it's not intuitive to anyone. If things like this were intuitive, the industry and humanity would look very different.
-
-
Barinzaya:
-
That's C in a nutshell
-
It is what's actually happening at the CPU level. The CPU doesn't know about arrays, structures, etc. It just deals in "load a value from/store a value to this address". It doesn't know nor care about the larger structure that that value may be a part of.
-
-
dmitsuki:
-
That's why people made new languages with new features
-
But fundamentally that is what is happening
-
It's also why certain security problems exist, you can read past the bounds of an array and read memory you shouldn't
-
Arrays